public class ThreadDemo03 {
    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();

        for (int i = 0; i < 10000; i++) {
            System.out.println(Thread.currentThread().getName() + i);

            if (i % 10 == 0) {
//                System.out.println("线程让位");
                Thread.yield();// 线程让位
            }
//            Thread.sleep(1000);
        }
    }
}


class MyThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(Thread.currentThread().getName() + i);
//            try {
////                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
    }
}